package com.ncf.jucai.mybatis.generator;

import java.util.List;

import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.PluginAdapter;
import org.mybatis.generator.api.dom.xml.Attribute;
import org.mybatis.generator.api.dom.xml.XmlElement;

public class InsertWithKeyGenerator extends PluginAdapter {

	@Override
    public boolean sqlMapInsertElementGenerated(XmlElement element,IntrospectedTable introspectedTable) {
		element.addAttribute(new Attribute("useGeneratedKeys", "true"));
		element.addAttribute(new Attribute("keyProperty", "id"));
        return super.sqlMapInsertElementGenerated(element,introspectedTable);
    }
	
	@Override
    public boolean sqlMapInsertSelectiveElementGenerated(XmlElement element,
            IntrospectedTable introspectedTable) {
		element.addAttribute(new Attribute("useGeneratedKeys", "true"));
		element.addAttribute(new Attribute("keyProperty", "id"));
        return super.sqlMapInsertSelectiveElementGenerated(element,introspectedTable);
    }

	@Override
	public boolean validate(List<String> warnings) {
		return true;
	}

}
